<%--
  Created by IntelliJ IDEA.
  User: 练钰华
  Date: 2025/11/5
  Time: 13:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.math.BigDecimal" %>
<html>
<head>
  <title>员工列表 - 员工信息管理系统</title>
  <link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css">
</head>
<body>
<%-- 顶部导航栏 --%>
<div class="navbar">
  <div class="container">
    <h1>员工信息管理系统</h1>
    <div class="user-info">
      <span>欢迎您，${loginUser.username}！</span>
      <a href="${pageContext.request.contextPath}/LogoutServlet" class="btn logout-btn">退出登录</a>
    </div>
  </div>
</div>

<%-- 员工列表内容 --%>
<div class="container">
  <div class="table-container">
    <h2>员工信息列表</h2>
    <div class="table-actions">
      <a href="${pageContext.request.contextPath}/employee/add.jsp" class="btn add-btn">添加员工</a>
    </div>
    <table>
      <thead>
      <tr>
        <th>ID</th>
        <th>姓名</th>
        <th>部门</th>
        <th>职位</th>
        <th>薪资</th>
        <th>入职日期</th>
        <th>操作</th>
      </tr>
      </thead>
      <tbody>
      <%-- 循环展示员工列表 --%>
      <c:forEach items="${employees}" var="emp">
        <tr>
          <td>${emp.id}</td>
          <td>${emp.name}</td>
          <td>${emp.department}</td>
          <td>${emp.position}</td>
          <td>${emp.salary.setScale(2)}</td> <%-- 薪资保留2位小数 --%>
          <td>${emp.hire_date}</td>
          <td>
            <a href="${pageContext.request.contextPath}/EmployeeServlet?action=view&id=${emp.id}" class="btn action-btn view-btn">查看</a>
            <a href="${pageContext.request.contextPath}/EmployeeServlet?action=editPre&id=${emp.id}" class="btn action-btn edit-btn">编辑</a>
            <a href="${pageContext.request.contextPath}/EmployeeServlet?action=delete&id=${emp.id}" class="btn action-btn delete-btn" onclick="return confirm('确定要删除该员工吗？')">删除</a>
          </td>
        </tr>
      </c:forEach>
      </tbody>
    </table>
    <%-- 无员工数据时显示 --%>
    <c:if test="${empty employees}">
      <div style="text-align: center; padding: 30px; color: #7f8c8d;">
        暂无员工数据，点击"添加员工"创建第一条数据
      </div>
    </c:if>
  </div>
</div>
</body>
</html>